package com.TingBer.view.buttons;

import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.swing.*;
import java.awt.*;
import java.io.InputStream;
import java.net.URL;
import java.util.Objects;
import java.util.function.Supplier;

public class BaseButton extends JButton {
    public BaseButton() {
        super();
        this.setBorder(null);
        this.setBackground(null);
    }

    public BaseButton(String text) {
        super(text);
        this.setBorder(null);
        this.setBackground(null);
        setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.setPreferredSize(new Dimension(80,30));
//        this.setContentAreaFilled(false);
    }

    public BaseButton(Icon icon) {
        super(icon);
        this.setBorder(null);
        this.setBackground(null);
        setCursor(new Cursor(Cursor.HAND_CURSOR));
    }

    public BaseButton(String text, ImageIcon imageIcon) {

        super(text,imageIcon);
        this.setRolloverIcon(imageIcon);
        this.setBorder(null);
        this.setBackground(null);
        setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.setBorderPainted(false);

        this.setFocusPainted(false);

        this.setContentAreaFilled(false);

        this.setFocusable(true);

        this.setMargin(new Insets(0, 0, 0, 0));
        this.setPreferredSize(new Dimension(imageIcon.getIconWidth(),imageIcon.getIconHeight()));
        this.setSize(80,50);
//        this.setRolloverIcon();
//        this.setHorizontalTextPosition(SwingConstants.CENTER);
//        this.setVerticalTextPosition(SwingConstants.CENTER);
    }

    public void setClassPathIcon(String path) {

        // 打开资源的InputStream
        try {

            this.setSize(100,40);
            ImageIcon icon = new ImageIcon(path);
            this.setIcon(icon);
        } catch (Exception e) {
            e.getStackTrace();
        }
    }
}
